<?php
include_once ("../Login/databaseconnection.php");
	
	$Exam_Name=$_POST['Exam_Name'];
$Subject=$_POST['Subject'];
	$Year=$_POST['Year'];
	$No_Of_Sat_Students=$_POST['No_Of_Sat_Students'];
	$No_Of_Passed_Students=$_POST['No_Of_Passed_Students'];
	  $SchName=$_POST['SchName'];
   $name=explode(",",$SchName);
    $nam=$name[0];
$tn=count($name);
for($i=1;$i<$tn;$i++)
{
if(empty($adr))
{
$adr=$name[$i];
}
else
{
$adr=$adr.",".$name[$i];
}
}
$results= mysql_query("SELECT * FROM school Where Name='$nam' AND Address='$adr'");
if($row = mysql_fetch_array($results))
{
 $School_Id=$row['School_Id'];
}
	date_default_timezone_set("Europe/Paris");
    $t_d=date("Y-m-d");
	
if($SchName!=""&&$Exam_Name!=""&&$Year!=""&&$No_Of_Sat_Students!=""&&$No_Of_Passed_Students!=""&&$Subject!="")
	{
	if($_SESSION['Access_Type']=="Teacher in Charge")
{
   $NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
  
   if($School_Id==$Own_School_Id)
	{
	 mysql_query("INSERT INTO exam(School_Id,Exam_Name,Subject,Year,No_Of_Sat_Students,No_Of_Passed_Students,Last_Updated_Date) VALUES('$School_Id','$Exam_Name','$Subject','$Year','$No_Of_Sat_Students','$No_Of_Passed_Students','$t_d')");
if(mysql_affected_rows()==1)
  {
$_SESSION['error']="This record is successfully registered!";
$_SESSION['OK']="OK";
$_SESSION['Exam_Name']=$Exam_Name;
$_SESSION['School_Id']=$School_Id;
$_SESSION['Subject']=$Subject;
$_SESSION['Year']=$Year;
  }

  if(mysql_affected_rows()==0)
  {
$_SESSION['error']="Sorry unable to register this record!";
  }
	}
	else
	   {
	   $_SESSION['errornotallo']="Sorry you are not allowed to do this!";
	   }
	}
	}
	else if($_SESSION['Access_Type']=="Administrator")
{
 mysql_query("INSERT INTO exam(School_Id,Exam_Name,Year,No_Of_Sat_Students,No_Of_Passed_Students,Last_Updated_Date) VALUES('$School_Id','$Exam_Name','$Year','$No_Of_Sat_Students','$No_Of_Passed_Students','$t_d')");
if(mysql_affected_rows()==1)
  {
$_SESSION['error']="This record is successfully registered!";
$_SESSION['OK']="OK";
$_SESSION['Exam_Name']=$Exam_Name;
$_SESSION['School_Id']=$School_Id;
$_SESSION['Subject']=$Subject;
$_SESSION['Year']=$Year;
  }
  if(mysql_affected_rows()==0)
  {
$_SESSION['error']="Sorry unable to register this record!";
  }
  }
  else
	   {
	   $_SESSION['errornotallo']="Sorry you are not allowed to do this!";
	   }
  }

  if($SchName==""||$Exam_Name==""||$Subject==""||$Year==""||$No_Of_Sat_Students==""||$No_Of_Passed_Students=="")
	{
	
	$_SESSION['errorin']="All details are required Please fill all!";
  }
?>

